package com.es.spring.aop.chain;

import com.es.spring.aop.common.TargetMethod;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author 二十
 * @since 2021/11/9 9:48 下午
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class JdkDynamic implements InvocationHandler {

    private Object target;

    private AbstractSlot head;


    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return head.proceed(new TargetMethod(target, method, args));
    }

    public Object getProxy() {
        return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), this);
    }
}
